# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 14:04
# @Author  : lt
# @Email   : lt@163.com
# @File    : add_lianxiren_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from selenium.webdriver.support.select import Select
class Add_Lianxi_Page(BasePage):
    # 联系人姓名输入框
    lianxiren_name = (By.ID, 'name')

    # 定位尊称输入框
    zuncheng_locator = (By.CSS_SELECTOR, '#saltname')

    # 定位客户输入框
    suoshu_locator = (By.ID, 'customer_name')

    # 定位所属客户tbody
    tbody_locator = (By.CSS_SELECTOR, '#datas')

    # 定位确认按钮
    queren_locator = (By.CSS_SELECTOR, 'body > div:nth-child(8) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')

    # 定位职位输入框
    zhiwei_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(3) > td:nth-child(4) > input')

    # 定位电话输入框
    mobile_locator = (By.NAME, 'telephone')

    # 定位邮箱输入框
    email_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(4) > td:nth-child(4) > input')

    # 定位QQ输入框
    qq_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > input')

    # 定位邮编输入框
    youbian_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(5) > td:nth-child(4) > input')

    # 定位联系地址
    adress_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(6) > td:nth-child(2) > input')

    # 定位备注输入框
    description_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(7) > td:nth-child(2) > textarea')

    # 定位保存按钮
    baocun_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)')

    # 定位添加成功
    tianjia_suceful_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')

    # 输入姓名
    def lianxiren_shuru(self,lianxiren):
        self.driver.find_element(*self.lianxiren_name).send_keys(lianxiren)
    # 输入尊称
    def zuncheng_shuru(self,zuncheng):
        self.driver.find_element(*self.zuncheng_locator).send_keys(zuncheng)
    # 点击客户
    def kehu_click(self):
        self.driver.find_element(*self.suoshu_locator).click()
    # 选择指定客户
    def kehu_tobdy(self,kehu):
        tobdy = self.driver.find_element(*self.tbody_locator)
        trs = tobdy.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == kehu:
                tds[0].find_element(By.CSS_SELECTOR, '[name="customer"]').click()
    # 点击确定
    def queren_click(self):
        self.driver.find_element(*self.queren_locator).click()
    # 输入职位
    def zhiwei_shuru(self,zhiwei):
        self.driver.find_element(*self.zhiwei_locator).send_keys(zhiwei)
    # 输入电话
    def mobile_shuru(self,moible):
        self.driver.find_element(*self.mobile_locator).send_keys(moible)
    # 输入email
    def email_shuru(self,email):
        self.driver.find_element(*self.email_locator).send_keys(email)
    # 输入qq
    def qq_shuru(self,qq):
        self.driver.find_element(*self.qq_locator).send_keys(qq)
    # 输入邮编
    def youbian_shuru(self,youbian):
        self.driver.find_element(*self.youbian_locator).send_keys(youbian)
    # 输入联系地址
    def adress_shuru(self,adress):
        self.driver.find_element(*self.adress_locator).send_keys(adress)
    # 点击保存
    def baocun_click(self):
        self.driver.find_element(*self.baocun_locator).click()
    # 断言
    def tianjia_succefulaa(self):
        text = self.driver.find_element(*self.tianjia_suceful_locator)
        return text